package com.twoke.wx;

import com.twoke.wx.api.IWeiXinAuthApi;
import com.twoke.wx.api.IWeiXinCodeApi;
import com.twoke.wx.api.IWeiXinSubscribeMessageApi;
import com.twoke.wx.api.impl.WeiXinAuthApiImpl;
import com.twoke.wx.api.impl.WeiXinCodeApiImpl;
import com.twoke.wx.api.impl.WeiXinSubscribeMessageApiImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @author WDD
 * @desc
 * @date 2020/7/1
 */
@Configuration
@EnableConfigurationProperties(WeChatSdkProperties.class)
public class WeChatSdkAutoConfiguration {

    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    @Bean
    public IWeiXinCodeApi weiXinCodeApi(WeChatSdkProperties properties){
        return new WeiXinCodeApiImpl(properties.getAppid(),properties.getSecret());
    }

    @Bean
    public IWeiXinAuthApi weiXinAuthApi(WeChatSdkProperties properties){
        return new WeiXinAuthApiImpl(properties.getAppid(),properties.getSecret());
    }

    @Bean
    public IWeiXinSubscribeMessageApi subscribeMessageApi(WeChatSdkProperties properties){
        return new WeiXinSubscribeMessageApiImpl(properties.getAppid(),properties.getSecret());
    }

}
